package com.bwie.web.controller;

import com.bwie.pojo.User;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

//@RestController
@RequestMapping("/user")
@Api(value = "用户管理",tags = "/user")
public class UserController2 {

    //以下这些都是swagger类操作的（不太懂）
    //根据id查询用户
    @GetMapping("/{id}")
    //方法操作的描述
    @ApiOperation(value="根据id查询",notes = "根据编号查询用户数据",tags = "/user")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="用户编号",required = true, paramType = "path")
    })
    //返回信息的描述
    @ApiResponses({
            @ApiResponse(code = 204,message = "成功没有内容"),
            @ApiResponse(code = 401,message = "未认证")
    })
    public User listById(@PathVariable String id, HttpServletRequest request){

//        try {
//            Thread.sleep(5000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        int d=1/0;
        //获取远程调用的端口
        int port = request.getServerPort();
        //模拟从数据库查询出的数据
//        User user=new User(id,"Rose"+id);
        User user=new User(id,"来自"+port+"端口的Rose"+id);
        return user;
    }
}
